/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package com.nicolascarrascob.pds.serviciosoap.orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import com.nicolascarrascob.pds.serviciosoap.orm.*;

public class PeliculaDAOImpl implements com.nicolascarrascob.pds.serviciosoap.orm.dao.PeliculaDAO {
	public Pelicula loadPeliculaByORMID(int id) throws PersistentException {
		try {
			PersistentSession session = com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession();
			return loadPeliculaByORMID(session, id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula getPeliculaByORMID(int id) throws PersistentException {
		try {
			PersistentSession session = com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession();
			return getPeliculaByORMID(session, id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula loadPeliculaByORMID(int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession();
			return loadPeliculaByORMID(session, id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula getPeliculaByORMID(int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession();
			return getPeliculaByORMID(session, id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula loadPeliculaByORMID(PersistentSession session, int id) throws PersistentException {
		try {
			return (Pelicula) session.load(com.nicolascarrascob.pds.serviciosoap.orm.Pelicula.class, new Integer(id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula getPeliculaByORMID(PersistentSession session, int id) throws PersistentException {
		try {
			return (Pelicula) session.get(com.nicolascarrascob.pds.serviciosoap.orm.Pelicula.class, new Integer(id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula loadPeliculaByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Pelicula) session.load(com.nicolascarrascob.pds.serviciosoap.orm.Pelicula.class, new Integer(id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula getPeliculaByORMID(PersistentSession session, int id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Pelicula) session.get(com.nicolascarrascob.pds.serviciosoap.orm.Pelicula.class, new Integer(id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula[] listPeliculaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession();
			return listPeliculaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula[] listPeliculaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession();
			return listPeliculaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula[] listPeliculaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.nicolascarrascob.pds.serviciosoap.orm.Pelicula as Pelicula");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Pelicula[]) list.toArray(new Pelicula[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula[] listPeliculaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.nicolascarrascob.pds.serviciosoap.orm.Pelicula as Pelicula");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Pelicula[]) list.toArray(new Pelicula[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula loadPeliculaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession();
			return loadPeliculaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula loadPeliculaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession();
			return loadPeliculaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula loadPeliculaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Pelicula[] peliculas = listPeliculaByQuery(session, condition, orderBy);
		if (peliculas != null && peliculas.length > 0)
			return peliculas[0];
		else
			return null;
	}
	
	public Pelicula loadPeliculaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Pelicula[] peliculas = listPeliculaByQuery(session, condition, orderBy, lockMode);
		if (peliculas != null && peliculas.length > 0)
			return peliculas[0];
		else
			return null;
	}
	
	public static java.util.Iterator iteratePeliculaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession();
			return iteratePeliculaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePeliculaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession();
			return iteratePeliculaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePeliculaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.nicolascarrascob.pds.serviciosoap.orm.Pelicula as Pelicula");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePeliculaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From com.nicolascarrascob.pds.serviciosoap.orm.Pelicula as Pelicula");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula createPelicula() {
		return new com.nicolascarrascob.pds.serviciosoap.orm.Pelicula();
	}
	
	public boolean save(com.nicolascarrascob.pds.serviciosoap.orm.Pelicula pelicula) throws PersistentException {
		try {
			com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().saveObject(pelicula);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(com.nicolascarrascob.pds.serviciosoap.orm.Pelicula pelicula) throws PersistentException {
		try {
			com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().deleteObject(pelicula);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(com.nicolascarrascob.pds.serviciosoap.orm.Pelicula pelicula)throws PersistentException {
		try {
			if(pelicula.getClasificacion() != null) {
				pelicula.getClasificacion().pelicula.remove(pelicula);
			}
			
			if(pelicula.getGenero() != null) {
				pelicula.getGenero().pelicula.remove(pelicula);
			}
			
			com.nicolascarrascob.pds.serviciosoap.orm.Sala[] lSalas = pelicula.sala.toArray();
			for(int i = 0; i < lSalas.length; i++) {
				lSalas[i].setPelicula(null);
			}
			return delete(pelicula);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(com.nicolascarrascob.pds.serviciosoap.orm.Pelicula pelicula, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(pelicula.getClasificacion() != null) {
				pelicula.getClasificacion().pelicula.remove(pelicula);
			}
			
			if(pelicula.getGenero() != null) {
				pelicula.getGenero().pelicula.remove(pelicula);
			}
			
			com.nicolascarrascob.pds.serviciosoap.orm.Sala[] lSalas = pelicula.sala.toArray();
			for(int i = 0; i < lSalas.length; i++) {
				lSalas[i].setPelicula(null);
			}
			try {
				session.delete(pelicula);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(com.nicolascarrascob.pds.serviciosoap.orm.Pelicula pelicula) throws PersistentException {
		try {
			com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession().refresh(pelicula);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(com.nicolascarrascob.pds.serviciosoap.orm.Pelicula pelicula) throws PersistentException {
		try {
			com.nicolascarrascob.pds.serviciosoap.orm.CarteleraDeCinePersistentManager.instance().getSession().evict(pelicula);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Pelicula loadPeliculaByCriteria(PeliculaCriteria peliculaCriteria) {
		Pelicula[] peliculas = listPeliculaByCriteria(peliculaCriteria);
		if(peliculas == null || peliculas.length == 0) {
			return null;
		}
		return peliculas[0];
	}
	
	public Pelicula[] listPeliculaByCriteria(PeliculaCriteria peliculaCriteria) {
		return peliculaCriteria.listPelicula();
	}
}
